<?PHP
	// lors d'ajout dynamique d'un onglet pour un nouveau site, on passe le numéro du nouveau site, qu'on stocke dans $nb
	if(isset($this->request->data['nb'])) {
		$nb = $this->request->data['nb'];
	}
?>
<div class="formentier">
	
	<div class="topform">
		<div class="choix_services">
	<?PHP
		/* création des checkbox pour les services, $services contient les vox_blocs, les blocs_questions et les questions */
		foreach($services as $service) {
			echo '<div class="service">';
			echo $this->Form->label($service['info_VoxBloc']['libelle_vox_bloc'], $service['info_VoxBloc']['libelle_vox_bloc']);
			echo $this->Form->checkbox($service['info_VoxBloc']['libelle_vox_bloc'], array('id' => "checkbox_".$nb."_".$service['info_VoxBloc']['id_vox_bloc']."", 'name' => "site[".$nb."][bloc][".$service['info_VoxBloc']['id_vox_bloc']."][active]", 'onclick' => "toggleAffichageBloc(this.id);"));
			echo "</div>";
		}
	?>
		</div>
		<div class="infossite">
<?PHP
	foreach($questions_sites as $question) {
?>
	<script type="text/javascript">
		ajouterFait(<?PHP echo $nb; ?>, 'site<?PHP echo $nb; ?>_question_'+<?PHP echo $question['id_question']; ?>+'_reponses', new Array());
	</script>
<?PHP
		echo '<div id="site'.$nb.'_question_'.$question['id_question'].'">';
		echo '<input type="hidden" name="site['.$nb.'][question]['.$question['id_question'].'][active]" />';
		switch($question['type_reponse']) {
			case 'LISTE':
				echo $this->element('form_liste', array("question" => $question, "nb"=> $nb, "questionscombos" => $questionscombos));
				break;
			case 'ARTICLE':
				echo $this->element('form_article', array("question" => $question, "nb"=> $nb, "questionsavecarticles" => $questionsavecarticles));
				break;
			case 'OUINON':
				echo $this->element('form_ouinon', array("question" => $question, "nb"=> $nb));
				break;
			case 'ENTIER': 
				echo $this->element('form_entier', array("question" => $question, "nb"=> $nb));
				break;
			case 'TEXTE': 
				echo $this->element('form_texte', array("question" => $question, "nb"=> $nb));
				break;
			default:
				break;
		}
		echo '</div>';
?>
	<script type="text/javascript">
		ajouterFait(<?PHP echo $nb; ?>, 'site<?PHP echo $nb; ?>_question_'+<?PHP echo $question['id_question']; ?>, document.getElementById('site<?PHP echo $nb; ?>_question_' + <?PHP echo $question['id_question']; ?>));
<?PHP if($question['question_active_par_defaut'] == false): ?>
		cacherElement(<?PHP echo $nb; ?>, 'site<?PHP echo $nb; ?>_question_'+<?PHP echo $question['id_question']; ?>);
<?PHP endif; ?>
	</script>
<?PHP
	}
?>
		</div>
	</div>
<?PHP
	echo '<div style="clear:both; padding:1px;"></div>';
	foreach($services as $service) {
		/* parcours les vox_bloc (services) */
		echo '<div style="display:none;" id="bloc_'.$nb.'_'.$service['info_VoxBloc']['id_vox_bloc'].'">';
		echo '<div class="titre_clic" onclick="$(this).next(\'.togglebox\').slideToggle(\'fast\');">'.$service['info_VoxBloc']['libelle_vox_bloc'].'</div>';
		echo '<div class="togglebox">';
		foreach($service['BlocsQuestions'] as $bloc) {
			/* parcours les bloc_questions du vox_bloc courant */
			echo '<div class="form_categorie">';
			echo '<div class="titre_categorie">'.$bloc['info_BlocQuestion']['description_bloc'].'</div>';
			foreach($bloc['Questions'] as $question) {
				/* parcours les questions du bloc_question courant */
				echo '<div id="site'.$nb.'_question_'.$question['id_question'].'">';
				echo '<input type="hidden" name="site['.$nb.'][bloc]['.$service['info_VoxBloc']['id_vox_bloc'].'][question]['.$question['id_question'].'][active]" />';
?>
	<script type="text/javascript">
		ajouterFait(<?PHP echo $nb; ?>, 'site<?PHP echo $nb; ?>_question_'+<?PHP echo $question['id_question']; ?>+'_reponses', new Array());
	</script>
<?PHP
				switch($question['type_reponse']) {
					case 'LISTE':
						echo $this->element('form_liste', array("voxbloc" => $service['info_VoxBloc']['id_vox_bloc'], "question" => $question, "nb"=> $nb, "questionscombos" => $questionscombos));
						break;
					case 'ARTICLE':
						echo $this->element('form_article', array("voxbloc" => $service['info_VoxBloc']['id_vox_bloc'], "question" => $question, "nb"=> $nb, "questionsavecarticles" => $questionsavecarticles));
						break;
					case 'OUINON':
						echo $this->element('form_ouinon', array("voxbloc" => $service['info_VoxBloc']['id_vox_bloc'], "question" => $question, "nb"=> $nb));
						break;
					case 'ENTIER': 
						echo $this->element('form_entier', array("voxbloc" => $service['info_VoxBloc']['id_vox_bloc'], "question" => $question, "nb"=> $nb));
						break;
					case 'TEXTE': 
						echo $this->element('form_texte', array("voxbloc" => $service['info_VoxBloc']['id_vox_bloc'], "question" => $question, "nb"=> $nb));
						break;
					default:
						break;
				}
				echo '</div>';
				
				// mode moteur d'inférence :
				// ajout de l'élément à la base des faits
				// ajout des éventuels règles
?>
	<script type="text/javascript">
		ajouterFait(<?PHP echo $nb; ?>, 'site<?PHP echo $nb; ?>_question_'+<?PHP echo $question['id_question']; ?>, document.getElementById('site<?PHP echo $nb; ?>_question_' + <?PHP echo $question['id_question']; ?>));
<?PHP if($question['question_active_par_defaut'] == false): ?>
		cacherElement(<?PHP echo $nb; ?>, 'site<?PHP echo $nb; ?>_question_'+<?PHP echo $question['id_question']; ?>);
<?PHP endif; ?>
	</script>
<?PHP
			// fin du mode moteur d'inférence
			}
			echo '</div>';
		}
		echo '</div>';
		echo '</div>';
	}
?>
</div>

<script type="text/javascript">
	initBaseDeFait(<?PHP echo $nb; ?>);
</script>